package me.magicall.db.springjdbc.tmp;

import java.util.Collection;

import me.magicall.coll.CollFactory;
import me.magicall.coll.ElementTransformer;
import me.magicall.db.Condition;
import me.magicall.db.ConditionOperator;
import me.magicall.db.OneFieldComparator;
import me.magicall.db.dao2.Dao2;
import me.magicall.db.dao2.Query;
import me.magicall.db.model.BaseModel.MapModel;
import me.magicall.db.springjdbc.dao2.Table;
import me.magicall.db.util.PageInfo;

public class Biz {

	private static final String[] STATIC_MODEL_NAMES = {//
	"baseStation",//
			"consts",//
			"device", "deviceBrand", "deviceHealthState", "deviceProduct", "deviceType", "deviceType0", "deviceUsingState",//
			"maintenanceAgentCompany", "maintenanceAgentStation", "mobileCompany",//
			"region", "role", "roleFunction",//
			"scheduledReceivingState", "serviceState", "serviceType", "specialty", "staff",//
			"storeInReason", "storeOutReason", "supportTaskResult",//
			"taskSource", "taskState"//
	};
	private Table table;

	private Dao2<MapModel<?>> dao2;

	private static boolean isStatic(final String modelName) {
		for (final String s : STATIC_MODEL_NAMES) {
			if (s.equalsIgnoreCase(modelName)) {
				return true;
			}
		}
		return false;
	}

//	public MapModel<?> getOne(final Query<MapModel<?>> queryConfig) {
//		final List<MapModel<?>> list = list(queryConfig);
//		return Kits.LIST.isEmpty(list) ? null : list.get(0);
//	}

	private static final ElementTransformer<String, String> FIELD_NAME_TO_MODEL_NAME = new ElementTransformer<String, String>() {
		@Override
		public String transform(final int index, final String element) {
			final int dotIndex = element.indexOf('.');
			return dotIndex < 0 ? element : element.substring(0, dotIndex);
		}
	};

//	public List<MapModel<?>> list(final Query<MapModel<?>> queryConfig) {
//		final List<String> fieldsNames = queryConfig.getRefedModelClasses();
//		final List<String> modelNames = Kits.LIST.transform(fieldsNames, FIELD_NAME_TO_MODEL_NAME);
//		for (final String modelName : modelNames) {
//			if (isStatic(modelName)) {
////TODO
//			}
//		}
//		return null;
//	}

	public static void main(final String[] args) {
		final Collection<Integer> ids = CollFactory.L.asList(1, 2, 3, 4, 5, 6);
		final Query<MapModel<?>> queryConfig = new Query<MapModel<?>>();
		queryConfig.addConditions(new Condition("id", ConditionOperator.IN, ids));
		queryConfig.setFieldComparator(OneFieldComparator.ID_ASC);
		queryConfig.setPageInfo(PageInfo.ALL_PAGE_INFO);

	}
}
